#include "Printer.h"
#include "Analyze.h"
#include "Reader.h"
#include <iostream>
#include <fstream>
#include <iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<cmath>
#include <cstring>

Printer::Printer(string fl)

{
        int n = fl.length()-7;
        this->Nameoutlog=fl.substr(0,n)+"_FE.log";
        this->Nameoutconv=fl.substr(0,n)+"_FE_Conv.log";

}

void Printer::ConvergencePrint(vector<long double> vec){

    FILE *enerfile;
    int size = vec.size();
    char filein[1000];
    strcpy(filein, this->Nameoutconv.c_str());
    enerfile = fopen(filein,"w");
                for(int i = 0; i<size; i++){
                    fprintf (enerfile, "	%.5d	%Lf \n", (i+1), vec[i]);
                }
}

void Printer::AnalyzePrint(Analyze* DAT){

    long double FE = DAT->FreeEnergy();
    long double IE = DAT->MeanInternalEnergy();
    long double ENT = DAT->Entropy();

    cout  << FE << " " << IE << " " << ENT << endl;
    printf("Results:\n");
    printf("Free Energy = 	%.5Lf \n", FE);
    printf("Mean Internal Energy = 	%.5Lf \n", IE);
    printf("Entropy = %.5Lf", ENT);


    FILE *enerfile;
    char filein[1000];
    strcpy(filein, this->Nameoutlog.c_str());
    enerfile = fopen(filein,"w");
    fprintf(enerfile,"Output Log");
    fprintf(enerfile,filein);
    fprintf(enerfile,"Free Energy = 	%.5Lf \n", FE);
    fprintf(enerfile,"Mean Internal Energy = 	%.5Lf \n", IE);
    fprintf(enerfile,"Entropy = %.5Lf \n", ENT);


}

